<template>
  <!-- <div style="height:520px;"> -->
    <div>
    <FilterTable
      ref="table"
      height="450"
      :columns="columns"
      :fetchapi="fetchApi"
      :isSelectColumn="isSelectColumn"
      :params="fetchParams"
      :datakey="'records'"
      columnsRef='customerManage_continueManage_record_applyInfoShow_01'
      :isPagination="isPagination"
      :onColumnsChange="columns => this.columns = columns"
    ></FilterTable>

    <!-- 编辑 -->
    <BaseDialog
      title="战败申请"
      width="700px"
      destroyOnClose
      :visible.sync="visibleFollowInfo"
      :containerStyle="{height: 'calc(100% - 60px)', overflow: 'auto', paddingBottom: '60px'}"
    >
      <applyaddDlg
        ref="followInfoDlg"
        :type="handleType"
        :rowData="formData"
        @close="closeFollowInfo"
      />
    </BaseDialog>

    <!-- 编辑 -->
    <BaseDialog
      title="延续申请"
      width="700px"
      destroyOnClose
      :visible.sync="visibleApplyInfo"
      :containerStyle="{height: 'calc(100% - 60px)', overflow: 'auto', paddingBottom: '60px'}"
    >
      <applyInsertDlg
        ref="applyInsertDlg"
        :type="handleType"
        :rowData="formData"
        @close="closeFollowInfo2"
      />
    </BaseDialog>
  </div>
</template>
<script>
import { dictionary } from '@/utils/dictMixin';
import { followInfo } from '@/api/cms-api/customerManage/continueManage/record/index';
import { addCarInfo } from '@/api/cms-api/customerManage/continueManage/record/index';
import { delCarInfo } from '@/api/cms-api/customerManage/continueManage/record/index';
import { delFollow } from '@/api/cms-api/customerManage/continueManage/record/index';
import { applyInfo } from '@/api/cms-api/customerManage/continueManage/record/index';
import followInfoDlg from '@/pages/cms-pages/customerManage/continueManage/record/followEdit';
import applyaddDlg from '@/pages/cms-pages/customerManage/continueManage/record/applyadd';
import applyInsertDlg from '@/pages/cms-pages/customerManage/continueManage/record/applyInsert';
import { formatdateByTime } from '@/utils/index';
import { formatdateByDay } from '@/utils/index';
export default {
  mixins: [dictionary],
  components: {
    followInfoDlg,
    applyaddDlg,
    applyInsertDlg
  },
  props: {
    value: {
      type: Number,
      required: true
    },
    infoBasic: {
      type: String,
      required: true
    }
  },
  data() {
    return {
      isSelectColumn: false,
      flterValue: {}, //参数
      fetchApi: applyInfo, //ipa 接口
      isPagination: false,
      visibleFollowInfo: false,
      visibleApplyInfo: false,
      formData: {},
      rowq: { projectId: this.value },
      handleType: '',
      columns: this.creatHeader(),
      fetchParams: { projectId: this.value } //ipa 接口
    };
  },
  created() {
    this.init();
  },
  methods: {
    formatDates: function(value) {
      // 这里的 value 就是需要过滤的数据
      if (value == null || value == '') {
        return '';
      }
      var date = new Date(value);
      var year = date.getFullYear();
      var month = date.getMonth() + 1;
      var day = date.getDate();
      return year + '-' + month + '-' + day;
    },
    //关闭详情
    closeFollowInfo(val, type) {
      this.visibleFollowInfo = false;
      if (type === 'refresh') {
        this.fetchParams = { ...this.fetchParams };
      }
    },
    closeFollowInfo2(val, type) {
      this.visibleApplyInfo = false;
      if (type === 'refresh') {
        this.fetchParams = { ...this.fetchParams };
      }
    },
    editHandle(row) {
      console.log(row);
      this.formData = row;
      this.handleType = 'edit';
      this.visibleFollowInfo = true;
    },
    async del(followId) {
      this.res = await delFollow(followId);
      this.fetchParams = { ...this.fetchParams };
    },
    deleHandle(followId) {
      this.del(followId);
    },
    async saveDialog(data, projectId) {
      this.res = await addCarInfo(data, projectId);
      this.fetchParams = { ...this.fetchParams }; //刷新
      this.visibleProduct = false; //测试
    },
    closeProduct(data) {
      console.log(data);
      this.saveDialog(data.data, this.value);
    },
    productHandle() {
      this.handleType = 'add';
      this.formData = this.rowq;
      this.visibleFollowInfo = true;
    },
    productHandlea() {
      this.handleType = 'add';
      this.formData = this.rowq;
      this.visibleApplyInfo = true;
    },
    //初始化数据
    init() {
      console.log('行id---->', this.value);
      console.log('是否编辑---->', this.infoBasic);
      //赋值
      // this.initForm.forEach(x => {
      //     x.initialValue = data.row[x.fieldName];
      // });
    },
    //table表头和数据源
    creatHeader() {
      return [
        {
          title: '序号',
          dataIndex: 'index',
          width: 80,
          sorter: true,
          render: props => {
            return <span>{props.row.index + 1}</span>;
          }
        },
        {
          title: '申请类型',
          dataIndex: 'applyType',
          sorter: true,
          render: props => {
            //编码转汉字
            return <span>{this.createDictText(props.row.applyType, '2522')}</span>;
          }
        },
        {
          title: '战败类型',
          dataIndex: 'defeatType',
          sorter: true,
          render: props => {
            //编码转汉字
            return <span>{this.createDictText(props.row.defeatType, '2523')}</span>;
          }
        },
        { title: '战败品牌', dataIndex: 'defeatBrandStr', sorter: true },
        { title: '战败车型', dataIndex: 'defeatModelStr', sorter: true },
        { title: '战败/延续原因', dataIndex: 'applyReason', sorter: true },
        {
          title: '申请时间',
          dataIndex: 'applyForDate',
          sorter: true,
          render: props => {
            if(props.row.applyType  == '25221001') {
                //战败
                  return <span>{formatdateByDay(props.row.applyDate)} </span>;
            }else {
              //延续
                return <span>{formatdateByDay(props.row.applyForDate)} </span>;
            }
          
          }
        },
        {
          title: '审核时间',
          dataIndex: 'reviewDate',
          sorter: true,
          render: props => {
            return <span>{formatdateByTime(props.row.reviewDate)} </span>;
          }
        },
        { title: '审核意见', dataIndex: 'checkDesc', sorter: true },
        {
          title: '审核状态',
          dataIndex: 'applyStatus',
          sorter: true,
          render: props => {
            //编码转汉字
            return <span>{this.createDictText(props.row.applyStatus, '2524')}</span>;
          }
        },
        { title: '审核人', dataIndex: 'reviewPersionName', sorter: true }
      ];
    }
  }
};
</script>

<style lang="less" scoped>
</style>
